package web.suzy.oj.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import web.suzy.oj.common.result.ResultBean;
import web.suzy.oj.pojo.entity.common.Announcement;
import web.suzy.oj.pojo.vo.AnnouncementVO;
import web.suzy.oj.service.admin.announcement.AdminAnnouncementService;

/**
 * YangSuzy 软件工作室
 * 类名: AnnouncementController
 * 描述: ---- 待定 -----
 * 功能: ---- 待定 -----
 *
 * @author YangSuzy
 * Date: 2022/11/25 20:34
 */
@RestController
@RequiresAuthentication
@RequestMapping("/api/admin")
public class AnnouncementController {
    @Autowired
    private AdminAnnouncementService adminAnnouncementService;

    /**
     * 方法名: getAnnouncementList
     * 描述: 获取公告列表
     *
     * @param limit       每页显示数目
     * @param currentPage 当前页
     * @return web.suzy.oj.common.result.ResultBean<com.baomidou.mybatisplus.core.metadata.IPage < web.suzy.oj.pojo.vo.AnnouncementVO>>
     * @date 2022/11/25 20:37
     * @auther YangSuzy
     **/
    @GetMapping("/announcement")
    @RequiresPermissions("announcement_admin")
    public ResultBean<IPage<AnnouncementVO>> getAnnouncementList(
            @RequestParam(value = "limit", required = false) Integer limit,
            @RequestParam(value = "currentPage", required = false) Integer currentPage) {
        return adminAnnouncementService.getAnnouncementList(limit, currentPage);
    }

    /**
     * 方法名: addAnnouncement
     * 描述: 管理员发布公告
     *
     * @param announcement 待发布公告
     * @return web.suzy.oj.common.result.ResultBean<java.lang.Void>
     * @date 2022/11/25 20:37
     * @auther YangSuzy
     **/
    @PostMapping("/announcement")
    @RequiresRoles("root")  // 只有超级管理员能操作
    @RequiresPermissions("announcement_admin")
    public ResultBean<Void> addAnnouncement(@RequestBody Announcement announcement) {
        return adminAnnouncementService.addAnnouncement(announcement);
    }

    /**
     * 方法名: updateAnnouncement
     * 描述: 管理员更新公告
     *
     * @param announcement 待更新公告
     * @return web.suzy.oj.common.result.ResultBean<java.lang.Void>
     * @date 2022/11/25 20:38
     * @auther YangSuzy
     **/
    @PutMapping("/announcement")
    @RequiresPermissions("announcement_admin")
    public ResultBean<Void> updateAnnouncement(@RequestBody Announcement announcement) {
        return adminAnnouncementService.updateAnnouncement(announcement);
    }

    /**
     * 方法名: deleteAnnouncement
     * 描述: 删除公告
     *
     * @param aid 公告ID
     * @return web.suzy.oj.common.result.ResultBean<java.lang.Void>
     * @date 2022/11/25 20:38
     * @auther YangSuzy
     **/
    @DeleteMapping("/announcement")
    @RequiresPermissions("announcement_admin")
    public ResultBean<Void> deleteAnnouncement(@RequestParam("aid") Long aid) {
        return adminAnnouncementService.deleteAnnouncement(aid);
    }
}
